package com.google.demo.Util;

import com.google.demo.R;
import com.google.demo.ScanQRCodeApp;

import android.content.res.Resources;

public enum ErrorCode {
	
	DATABASE_ERROR("0001"),
	FILESYSTEM_ERROR("0002"),
	INVALID_FILETYPE("0003"),
	MISSING_FIELD("0004"),
	API_FLOODING("0005"),
	INVALID_DATE("0006"),
	INVALID_DATA("0007"),
	TIME_OUT("0008") ,
	SMS_PHONE_FLOODING("0010"),
	SMS_DEVICEID_FLOODING("0011"),
	SERVER_ERROR("0012"),
	QR_CODE_NOT_FOUND("0015"),
	NETWORK_ERROR("NETWORK_ERROR");
	
	private String mErrorCode;
	
	ErrorCode(String errorCode)
	{
		mErrorCode = errorCode;
	}
	
	public static ErrorCode getErrorCode(String errorCode)
	{
		ErrorCode code = null;
		if(errorCode.equals("0001")){
			code= ErrorCode.DATABASE_ERROR;	
		}else if(errorCode.equals("0002")){
			code= ErrorCode.FILESYSTEM_ERROR;
		}else if(errorCode.equals("0003")){
			code= ErrorCode.INVALID_FILETYPE;
		}else if(errorCode.equals("0004")){
			code= ErrorCode.MISSING_FIELD;
		}else if(errorCode.equals("0005")){
			code= ErrorCode.API_FLOODING;
		}else if(errorCode.equals("0006")){
			code= ErrorCode.INVALID_DATE;
		}else if(errorCode.equals("0007")){
			code= ErrorCode.INVALID_DATA;
		}else if(errorCode.equals("0008")){
			code= ErrorCode.TIME_OUT;
		}else if(errorCode.equals("0010")){
			code= ErrorCode.SMS_PHONE_FLOODING;
		}else if(errorCode.equals("0011")){
			code= ErrorCode.SMS_DEVICEID_FLOODING;
		}else if(errorCode.equals("0012")){
			code= ErrorCode.SERVER_ERROR;
		}else if(errorCode.equals("0015")){
			code= ErrorCode.QR_CODE_NOT_FOUND;
		}else if(errorCode.equals("NETWORK_ERROR")){
			code = ErrorCode.NETWORK_ERROR;
		}else{
			code= ErrorCode.SERVER_ERROR;
		}
		return code;
	}
	
	public String getErrorMessage()
	{
		Resources res = ScanQRCodeApp.Instance().getResources();
		String mes="";
		if(mErrorCode.equals("0001")){
			mes=res.getString(R.string.DATABASE_ERROR);
		}else if(mErrorCode.equals("0002")){
			mes=res.getString(R.string.FILESYSTEM_ERROR);
		}else if(mErrorCode.equals("0003")){
			mes=res.getString(R.string.INVALID_FILETYPE);
		}else if(mErrorCode.equals("0004")){
			mes=res.getString(R.string.MISSING_FIELD);
		}else if(mErrorCode.equals("0005")){
			mes=res.getString(R.string.API_FLOODING);
		}else if(mErrorCode.equals("0006")){
			mes=res.getString(R.string.INVALID_DATE);
		}else if(mErrorCode.equals("0007")){
			mes=res.getString(R.string.INVALID_DATA);
		}else if(mErrorCode.equals("0008")){
			mes=res.getString(R.string.TIME_OUT);
		}else if(mErrorCode.equals("0010")){
			mes=res.getString(R.string.SMS_PHONE_FLOODING);
		}else if(mErrorCode.equals("0011")){
			mes=res.getString(R.string.SMS_DEVICEID_FLOODING);
		}else if(mErrorCode.equals("0012")){
			mes=res.getString(R.string.SERVER_ERROR);
		}else if(mErrorCode.equals("0015")){
			mes=res.getString(R.string.QR_CODE_NOT_FOUND);
		}else if(mErrorCode.equals("NETWORK_ERROR")){
			mes = res.getString(R.string.NETWORK_ERROR);
		}
		return mes;
	}
}
